package com.zzedu.web.controller;

import com.zzedu.annon.AccessPermission;
import com.zzedu.common.annotation.Log;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.enums.OperatorType;
import com.zzedu.common.enums.UserTypeEnumns;
import com.zzedu.common.utils.SecurityUtils;
import com.zzedu.manager.IZzStudentManager;
import com.zzedu.result.Result;
import com.zzedu.result.ResultEnum;
import com.zzedu.stu.req.QueryPageReport;
import com.zzedu.stu.req.QueryReport;
import com.zzedu.stu.req.UpdateStudentInfo;
import com.zzedu.stu.rsp.ApiZzStudentLearnReportVO;
import com.zzedu.stu.rsp.ApiZzStudentVO;
import com.zzedu.utils.BaseReq;
import com.zzedu.utils.PageData;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 学生信息
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    IZzStudentManager zzStudentManager;


    /**
     * 当前学生信息
     *
     * @param req
     * @return
     */
    @PostMapping(value = {"/info"}, produces = {MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.APPLICATION_JSON_VALUE})
    @Log(title = "学生-学生详情", businessType = BusinessType.APP_STUDENT, operatorType = OperatorType.MOBILE)
    public Result<ApiZzStudentVO> info(@Validated @RequestBody BaseReq req) {
        if(SecurityUtils.isStu()){
            return zzStudentManager.apiGetStudentInfo(SecurityUtils.getUserId());
        }
        Result<ApiZzStudentVO> result = new Result<>();
        ApiZzStudentVO apiZzStudentVO = new ApiZzStudentVO();
        apiZzStudentVO.setNickName(SecurityUtils.getLoginName()+"老师");
        apiZzStudentVO.setApiClzzVOList(Lists.newArrayList());
        result.setData(apiZzStudentVO);
        result.setResultCode(ResultEnum.SUCCESS.getCode());
        result.setResultMessage(ResultEnum.SUCCESS.getDesc());
        return result;
    }

    /**
     * 更新学生信息
     *
     * @param req
     * @return
     */
    @PostMapping(value = {"/updateInfo"}, produces = {MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.APPLICATION_JSON_VALUE})
    @Log(title = "学生-修改信息", businessType = BusinessType.APP_STUDENT, operatorType = OperatorType.MOBILE)
    @AccessPermission(value = {UserTypeEnumns.STUDENT})
    public Result updateInfo(@Validated @RequestBody BaseReq<UpdateStudentInfo> req) {
        return zzStudentManager.apiUpdateInfo(req.getData());
    }

    /**
     * 学生-学习报告列表
     *
     * @param req
     * @return
     */
    @PostMapping(value = {"/queryReport"}, produces = {MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.APPLICATION_JSON_VALUE})
    @Log(title = "学生-学习报告列表", businessType = BusinessType.APP_STUDENT, operatorType = OperatorType.MOBILE)

    public Result queryReport(@Validated @RequestBody BaseReq<QueryPageReport> req) {
        if(SecurityUtils.isStu()){
            return zzStudentManager.queryReport(req.getData());

        }
        Result<PageData<ApiZzStudentLearnReportVO>> result = new Result<>();
        result.setData(new PageData<>());
        result.setResultCode(ResultEnum.SUCCESS.getCode());
        result.setResultMessage(ResultEnum.SUCCESS.getDesc());
        return result;

    }
    /**
     * 学生-学习报告详情
     *
     * @param req
     * @return
     */
    @PostMapping(value = {"/queryReportInfo"}, produces = {MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.APPLICATION_JSON_VALUE})
    @Log(title = "学生-学习报告详情", businessType = BusinessType.APP_STUDENT, operatorType = OperatorType.MOBILE)
    @AccessPermission(value = {UserTypeEnumns.STUDENT})
    public Result queryReportInfo(@Validated @RequestBody BaseReq<QueryReport> req) {
        return zzStudentManager.queryReportInfo(req.getData());
    }
}
